Skip list element(data) access

Hi!

Is there anyway I can access the element (or data) of the skip list when I'm searching through the list of keys?  Maybe I'm not fully understanding how a Skip list works... I just don't know the point of storing data within each key if there is no easy way to access the data afterwards.

 

In my code I'm currently storing the Absolute Number as the Key and I would like to store an attribute as the data.  My code is a bit more complicated in that I'm searching through different baseline modules and looking at the linked object attributes but for demonstrative purposes it can be this:

 

Module m = current

Object o

string str

Skip list = createString()

 

for o in m do {

      string absn = o."Absolute Number"""

      put(list, absn, o."Test Run Date""")

}

//Now I want to look through my stored skip list

for str in list do {

      string printKey = (string key list)

      //string printData = (string data list)   <---------Is there a command such that I can bind the data to a string and print it out???

      print(printKey)  //this line will return all the keys

}
 

delete(list)

 


ABoucaud - Fri Jan 27 07:56:59 EST 2017

Re: Skip list element(data) access
O.Wilkop - Fri Jan 27 08:04:54 EST 2017

The "str" in your "for str in list do" gets assigned to the data you want for each loop, so try

print printKey " : " str"\n";

instead of your "print(printKey)"

 

 

Another option (if you know the key for which you want to retrieve the data already) is to use the find function:

 

Skip sl = createString();

put(sl, "x", "123");
put(sl, "y", "234");
put(sl, "z", "345");


string szOut = "";
if(find(sl, "x", szOut)){
    print "Value: " szOur"\n";
}

if(find(sl, "NotInList", szOut)){
    //won't be reached as "NotInList" is not in the skip list   
}

 

Re: Skip list element(data) access
ABoucaud - Fri Jan 27 09:11:06 EST 2017

O.Wilkop - Fri Jan 27 08:04:54 EST 2017

The "str" in your "for str in list do" gets assigned to the data you want for each loop, so try

print printKey " : " str"\n";

instead of your "print(printKey)"

 

 

Another option (if you know the key for which you want to retrieve the data already) is to use the find function:

 

Skip sl = createString();

put(sl, "x", "123");
put(sl, "y", "234");
put(sl, "z", "345");


string szOut = "";
if(find(sl, "x", szOut)){
    print "Value: " szOur"\n";
}

if(find(sl, "NotInList", szOut)){
    //won't be reached as "NotInList" is not in the skip list   
}

 

It worked of course! When I first tried to just print out str in my program i was getting all an output like "@!#*^&*T%$)(!@#&*!&@#".  Looking back I think maybe this was because that particular attribute (that was being stored as a data) didn't exist within that object maybe?  Anyhow both your methods work but I'm still trying to wrap my head around your second method and why that also prints out the data from the key. I guess szOut is just being assigned whatever data was stored at s1.  Very Interesting.  Thank you for the quick answer!!!